package com.yisu.auction.ewf.common.utils;

import org.apache.commons.lang.StringUtils;

/**
 * Created by 飞扬 on 2017/1/2.
 */
public class StringUtil {

    /**
     * 隐藏用户名称
     *
     * @param userName
     * @return
     */
    public static String hideUserName(String userName) {
        if (StringUtils.isEmpty(userName)) {
            return "匿名*";
        } else {
            return (userName).substring(0, 1) + "**";
        }
    }

    /**
     * 隐藏用户手机
     *
     * @param phone
     * @return
     */
    public static String hidePhone(String phone) {
        if (StringUtils.isEmpty(phone)) {
            return "**";
        } else {
            if (phone.length() > 6)
                return (phone).substring(0, 2) + "****" + phone.substring(phone.length() - 2, phone.length());
        }
        return phone;
    }

    /**
     * 通过特殊符号，隐藏文本内容
     *
     * @param sourceContent 源字符内容
     * @param length        要截取的长度
     * @param symbol        符号 比如 * /....
     * @return 隐藏后的字符
     */
    public static String hideContentBySymbol(String sourceContent, long length, String symbol) {
        if (StringUtils.isEmpty(sourceContent))
            return "";
        if (sourceContent.length() <= length) {
            return sourceContent;
        }
        return (sourceContent).substring(0, (int) length) + symbol;
    }
}
